const config = {
	// dev
	// api_base_url: 'http://127.0.0.1:9012/',
	// api_base_url_tools: 'http://127.0.0.1:9019/',
	// oss_base_url: 'https://mashangjie.oss-cn-qingdao.aliyuncs.com/',
	
	//production
	base_url:'http://member.mashangjie.shop/',
	api_base_url: 'https://mashangjie.shop/',
	api_base_url_tools: 'http://mashangjie.shop:9019/',
	oss_base_url: 'https://mashangjie-pro.oss-cn-beijing.aliyuncs.com/',
}
const myGetDistance = function GetDistance(lat1, lng1, lat2, lng2) {
	var radLat1 = lat1 * Math.PI / 180.0
	var radLat2 = lat2 * Math.PI / 180.0
	var a = radLat1 - radLat2
	var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(
		b / 2), 2)))
	s = s * 6378.137
	s = Math.round(s * 10) / 10
	return s
}

const yourFormatDateTime = function formatDateTime(timeStamp) {
	var date = new Date()
	date.setTime(timeStamp) // 精确到毫秒、如果没有到毫秒就 date.setTime(timeStamp*1000);
	var y = date.getFullYear()
	var m = date.getMonth() + 1
	m = m < 10 ? ('0' + m) : m
	var d = date.getDate()
	d = d < 10 ? ('0' + d) : d
	var h = date.getHours()
	h = h < 10 ? ('0' + h) : h
	var minute = date.getMinutes()
	var second = date.getSeconds()
	minute = minute < 10 ? ('0' + minute) : minute
	second = second < 10 ? ('0' + second) : second
	return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
}


const mygettime = function gettime(shorttime) {
	shorttime = shorttime.toString().length < 13 ? shorttime * 1000 : shorttime;
	let now = (new Date()).getTime();
	let cha = (now - parseInt(shorttime)) / 1000;

	if (cha < 43200) {
		// 当天
		return dateFormat(new Date(shorttime), "{A} {t}:{ii}");
	} else if (cha < 518400) {
		// 隔天 显示日期+时间
		return dateFormat(new Date(shorttime), "{Mon}月{DD}日 {A} {t}:{ii}");
	} else {
		// 隔年 显示完整日期+时间
		return dateFormat(new Date(shorttime), "{Y}-{MM}-{DD} {A} {t}:{ii}");
	}
}

function parseNumber(num) {
	return num < 10 ? "0" + num : num;
}

function dateFormat(date, formatStr) {
	let dateObj = {},
		rStr = /\{([^}]+)\}/,
		mons = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];

	dateObj["Y"] = date.getFullYear();
	dateObj["M"] = date.getMonth() + 1;
	dateObj["MM"] = parseNumber(dateObj["M"]);
	dateObj["Mon"] = mons[dateObj['M'] - 1];
	dateObj["D"] = date.getDate();
	dateObj["DD"] = parseNumber(dateObj["D"]);
	dateObj["h"] = date.getHours();
	dateObj["hh"] = parseNumber(dateObj["h"]);
	dateObj["t"] = dateObj["h"] > 12 ? dateObj["h"] - 12 : dateObj["h"];
	dateObj["tt"] = parseNumber(dateObj["t"]);
	dateObj["A"] = dateObj["h"] > 12 ? '下午' : '上午';
	dateObj["i"] = date.getMinutes();
	dateObj["ii"] = parseNumber(dateObj["i"]);
	dateObj["s"] = date.getSeconds();
	dateObj["ss"] = parseNumber(dateObj["s"]);

	while (rStr.test(formatStr)) {
		formatStr = formatStr.replace(rStr, dateObj[RegExp.$1]);
	}
	return formatStr;
}

export {
	config,
	myGetDistance,
	yourFormatDateTime,
	mygettime
}
